/*
 * 日志详情
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LogInfo extends StatefulWidget {
  final value;
  LogInfo({Key key, @required this.value}) : super(key: key);
  @override
  State<StatefulWidget> createState() {
    return LogInfoState();
  }
}

class LogInfoState extends State<LogInfo> {
  // 焦点
  FocusNode _focusNodeTask = new FocusNode(); // 对应任务
  FocusNode _focusNodeContent = new FocusNode(); // 具体事项
  FocusNode _focusNodeProjectInput = new FocusNode(); // 投入项目
  FocusNode _focusNodeCompleteSchedule = new FocusNode(); // 完成进度
  FocusNode _focusNodeCompleteTime = new FocusNode(); // 完成时间
  // 对应任务
  TextEditingController _taskController = new TextEditingController();
  // 具体事项
  TextEditingController _contentController = new TextEditingController();
  // 投入项目
  TextEditingController _projectInputController = new TextEditingController();
  // 完成进度
  TextEditingController _completeScheduleController =
      new TextEditingController();
  // 完成时间
  TextEditingController _completeTimeController = new TextEditingController();
  @override
  void initState() {
    initValue(); // 初始化值
    // 监听对应任务
    super.initState();
  }

  /*
   * 初始化值 
   */
  void initValue() {
    if (widget.value != null) {
      _taskController.text = widget.value['task'];
      _contentController.text = widget.value['content'];
      _projectInputController.text = widget.value['projectName'];
      _completeScheduleController.text = widget.value['schedule'].toString();
      _completeTimeController.text = widget.value['completionDate'];
    }
  }

  @override
  void dispose() {
    // 移除焦点监听
    _taskController.dispose();
    _contentController.dispose();
    _projectInputController.dispose();
    _completeTimeController.dispose();
    _completeScheduleController.dispose();
    super.dispose();
  }

  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    // 输入文本框区域
    Widget inputTextArea = new Container(
      margin: EdgeInsets.only(left: 10, right: 10),
      decoration: new BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(8)),
          color: Colors.white),
      child: new Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          _taskWidget(), // 对应任务
          new SizedBox(
            height: ScreenUtil().setHeight(20),
          ),
          _contentWidget(), // 具体事项
          new SizedBox(
            height: ScreenUtil().setHeight(20),
          ),
          _projectInput(), // 项目投入
          new SizedBox(
            height: ScreenUtil().setHeight(20),
          ),
          _schedule(), // 完成进度
          new SizedBox(
            height: ScreenUtil().setHeight(20),
          ),
          _completeTime(), // 完成时间
        ],
      ),
    );
    return Scaffold(
      appBar: AppBar(
        title: Text('${widget.value['userName']}-日志详情'),
      ),
      backgroundColor: Colors.white,
      // 外层添加一个手势，用于点击空白部分，回收键盘
      body: new ListView(
        children: [
          inputTextArea,
        ],
      ),
    );
  }

  /*
   * 对应任务 
   */
  Widget _taskWidget() {
    return TextFormField(
      decoration: InputDecoration(
        labelText: "对应任务",
      ),
      enabled: false,
      maxLines: 6,
      maxLength: 500,
      keyboardType: TextInputType.multiline,
      controller: _taskController,
      focusNode: _focusNodeTask,
    );
  }

  /*
   * 具体事项 
   */
  Widget _contentWidget() {
    return Card(
      child: Padding(
        padding: EdgeInsets.all(8.0),
        child: TextFormField(
          decoration: InputDecoration(
            labelText: "具体事项",
          ),
          enabled: false,
          maxLines: 5,
          maxLength: 500,
          keyboardType: TextInputType.multiline,
          controller: _contentController,
          focusNode: _focusNodeContent,
        ),
      ),
    );
  }

  /*
   * 项目投入
   */
  Widget _projectInput() {
    return TextFormField(
      decoration: InputDecoration(
        labelText: "项目投入",
      ),
      enabled: false,
      keyboardType: TextInputType.multiline,
      controller: _projectInputController,
      focusNode: _focusNodeProjectInput,
    );
  }

  /*
   * 完成进度
   */
  Widget _schedule() {
    return TextFormField(
      decoration: InputDecoration(
        labelText: "完成进度（%）",
      ),
      enabled: false,
      keyboardType: TextInputType.number,
      controller: _completeScheduleController,
      focusNode: _focusNodeCompleteSchedule,
    );
  }

  /*
   * 完成时间 
   */
  Widget _completeTime() {
    return TextFormField(
      decoration: InputDecoration(
        labelText: "完成时间",
      ),
      enabled: false,
      keyboardType: TextInputType.number,
      controller: _completeTimeController,
      focusNode: _focusNodeCompleteTime,
    );
  }
}
